package www.woniuxy.com.class112.controller;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import www.woniuxy.com.class112.dto.PolicyDto;
import www.woniuxy.com.class112.form.achievement.AchievementCompileFORM;
import www.woniuxy.com.class112.form.achievement.AchievementFdAllForm;
import www.woniuxy.com.class112.form.achievement.AddAchievementForm;
import www.woniuxy.com.class112.param.achievement.AchievementCompileParam;
import www.woniuxy.com.class112.param.achievement.AchievementFdAllParam;
import www.woniuxy.com.class112.param.achievement.AddAchievementParam;
import www.woniuxy.com.class112.service.AchievementService;
import www.woniuxy.com.class112.util.JwtUtil;
import www.woniuxy.com.class112.util.Result;

import javax.annotation.Resource;

@RestController
@RequestMapping("/achievement")
@Api(tags = "成过转化相关接口")
public class AchievementController {
    @Resource
    private AchievementService achievementService;
    @PostMapping("achievementfdAll")
    @ApiOperation("查询所有成过转化")
    public Result achievementfdAll(@RequestBody AchievementFdAllForm form)throws Exception{
        AchievementFdAllParam param = BeanUtil.toBean(form, AchievementFdAllParam.class);
        PageInfo<PolicyDto> policyDtos = achievementService.achievementfdAll(param);
        return Result.success("查询成功",policyDtos);
    }
    @PostMapping("userachievementfdAll")
    @ApiOperation("用户查询所有成过转化")
    public Result userachievementfdAll(@RequestBody AchievementFdAllForm form)throws Exception{
        AchievementFdAllParam param = BeanUtil.toBean(form, AchievementFdAllParam.class);
        PageInfo<PolicyDto> policyDtos = achievementService.userachievementfdAll(param);
        return Result.success("查询成功",policyDtos);
    }
    @GetMapping("/delistachievement")
    @ApiOperation("下架成过转化")
    public Result delistachievement(Long policyId)throws Exception{
        achievementService.delistachievement(policyId);
        return Result.success("下架成功",null);
    }
    @GetMapping("/enableachievement")
    @ApiOperation("发布成过转化")
    public Result enablebreeding(Long policyId)throws Exception{
        achievementService.enableachievement(policyId);
        return Result.success("发布成过转化成功",null);
    }
    @GetMapping("/deleteachievement")
    @ApiOperation("删除成过转化")
    public Result deletebreeding(Long policyId)throws Exception{
        achievementService.deleteachievement(policyId);
        return Result.success("删成过转化成功",null);
    }
    @PostMapping("/addachievement")
    @ApiOperation("添加成过转化")
    public Result addpolicy(@RequestBody AddAchievementForm form, @RequestHeader String token)throws Exception{
        Long userId = JwtUtil.getUserId(token);
        AddAchievementParam param = BeanUtil.toBean(form, AddAchievementParam.class);
        param.setCreaterId(userId);
        achievementService.addachievement(param);
        return Result.success("添加成过转化成功",null);
    }
    @PostMapping("/achievementCompile")
    @ApiOperation("修改成过转化")
    public Result compileachievement(@RequestBody AchievementCompileFORM form)throws Exception{
        AchievementCompileParam param = BeanUtil.toBean(form, AchievementCompileParam.class);
        achievementService.compileachievement(param);
        return Result.success("修改成过转化成功",null);
    }
    @GetMapping("/tapNUm")
    @ApiOperation("添加点击量")
    public Result tapNUm(Long id)throws Exception{
        achievementService.tapNUm(id);
        return Result.success("添加点击量成功",null);
    }

}
